package empox.pos.operator;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import empox.pos.R;

public class Operator extends Activity implements OnClickListener,
		OnItemClickListener {

	ListView lv;
	OperatorAdapter oa;
	DbOperator db;
	OperatorInfo[] oi;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.operator);

		db = new DbOperator();

		lv = (ListView) this.findViewById(R.id.operatorlist);
		lv.setOnItemClickListener(this);

		oa = new OperatorAdapter(this);
		try {
			oi = db.getAllOpertorInfo("root");
		} catch (Exception e) {
			oi = null;
			e.printStackTrace();
		}

		oa.setValue(oi);
		lv.setAdapter(oa);
		((Button) this.findViewById(R.id.operatorexit))
				.setOnClickListener(this);
	}

	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.operatorexit:
			this.setResult(0);
			break;
		}
		this.finish();
	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		String operator = ((TextView) ((LinearLayout) arg1).getChildAt(0))
				.getText().toString();
		this.setResult(1, new Intent().putExtra("operator", operator));
		this.finish();
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}
}
